/**
 * Created by zhangqingxi on 2017/3/15.
 */

/***
 * 业务标识添加
 */
$(function () {

    //表单提交
    $('#departmentSave').on('click',function () {
        var index=layer.confirm('是否确定保存？', {
            btn: ['确定','取消'] //按钮
        }, function(){
            $('#departmentForm').form('submit', {
                url: ROOT_PATH+'/workflow/flowBusiness/addFlowBusiness.shtml',
                onSubmit: function (param) {
                    var isValid = $(this).form('validate');
                    if (!isValid) {
                        layer.close(index);
                        layer.msg("请正确填写表单")
                    }
                    return $(this).form('validate');
                },
                success: function (result) {
                    var data = $.parseJSON(result);

                    if(data.success){
                        parent.$('#dg1').datagrid('load');
                        parent.layer.closeAll(); //先得到当前iframe层的索引
                    }else{
                        layer.msg(data.message,{time:1000,icon:2});
                    }


                }
            });
        });

    });

    /***
     * 信息验证
     */
    $.extend($.fn.validatebox.defaults.rules, {
        //验证业务标识唯一性
        checkIdentity : {
            validator: function (value) {
                var checkR=$.ajax({
                    async : false,
                    cache : false,
                    type : 'post',
                    url : ROOT_PATH+'/workflow/flowBusiness/checkBusinessIdentity.shtml',
                    data : {
                        identity:value
                    }
                }).responseText;
                var dataObj=$.parseJSON(checkR);//转换为json对象
                var flag=dataObj.success==true;
                if(!flag){
                    $('#identity_err').css('display','block');
                }else {
                    $('#identity_err').css('display','none');
                }
                return flag;
            },
            message: '当前业务标识已存在！'
        }
    });

});



